home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / aclocal-1.6 / python.m4 < prev    next >
Encoding:
M4 Source File  |  2005-10-16  |  6.4 KB  |  158 lines

  1. ## ------------------------
  2. ## Python file handling
  3. ## From Andrew Dalke
  4. ## Updated by James Henstridge
  5. ## ------------------------
  6.  
  7. # Copyright 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
  8.  
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13.  
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18.  
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. # 02111-1307, USA.
  23.  
  24. # AM_PATH_PYTHON([MINIMUM-VERSION])
  25.  
  26. # Adds support for distributing Python modules and packages.  To
  27. # install modules, copy them to $(pythondir), using the python_PYTHON
  28. # automake variable.  To install a package with the same name as the
  29. # automake package, install to $(pkgpythondir), or use the
  30. # pkgpython_PYTHON automake variable.
  31.  
  32. # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
  33. # locations to install python extension modules (shared libraries).
  34. # Another macro is required to find the appropriate flags to compile
  35. # extension modules.
  36.  
  37. # If your package is configured with a different prefix to python,
  38. # users will have to add the install directory to the PYTHONPATH
  39. # environment variable, or create a .pth file (see the python
  40. # documentation for details).
  41.  
  42. # If the MINIUMUM-VERSION argument is passed, AM_PATH_PYTHON will
  43. # cause an error if the version of python installed on the system
  44. # doesn't meet the requirement.  MINIMUM-VERSION should consist of
  45. # numbers and dots only.
  46.  
  47. AC_DEFUN([AM_PATH_PYTHON],
  48.  [
  49.   dnl Find a Python interpreter.  Python versions prior to 1.5 are not
  50.   dnl supported because the default installation locations changed from
  51.   dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
  52.   dnl in 1.5.
  53.   m4_define([_AM_PYTHON_INTERPRETER_LIST],
  54.         [python python2 python2.2 python2.1 python2.0 python1.6 python1.5])
  55.  
  56.   m4_if([$1],[],[
  57.     dnl No version check is needed.
  58.     # Find any Python interpreter.
  59.     AC_PATH_PROG([PYTHON], _AM_PYTHON_INTERPRETER_LIST)],[
  60.     dnl A version check is needed.
  61.     if test -n "$PYTHON"; then
  62.       # If the user set $PYTHON, use it and don't search something else.
  63.       AC_MSG_CHECKING([whether $PYTHON version >= $1])
  64.       AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
  65.                   [AC_MSG_RESULT(yes)],
  66.                   [AC_MSG_ERROR(too old)])
  67.     else
  68.       # Otherwise, try each interpreter until we find one that satisfies
  69.       # VERSION.
  70.       AC_CACHE_CHECK([for a Python interpreter with version >= $1],
  71.     [am_cv_pathless_PYTHON],[
  72.     for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST : ; do
  73.           if test "$am_cv_pathless_PYTHON" = : ; then
  74.             AC_MSG_ERROR([no suitable Python interpreter found])
  75.       fi
  76.           AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
  77.         done])
  78.       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
  79.       AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
  80.     fi
  81.   ])
  82.  
  83.   dnl Query Python for its version number.  Getting [:3] seems to be
  84.   dnl the best way to do this; it's what "site.py" does in the standard
  85.   dnl library.
  86.  
  87.   AC_CACHE_CHECK([for $am_cv_pathless_PYTHON version], [am_cv_python_version],
  88.     [am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
  89.   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
  90.  
  91.   dnl Use the values of $prefix and $exec_prefix for the corresponding
  92.   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
  93.   dnl distinct variables so they can be overridden if need be.  However,
  94.   dnl general consensus is that you shouldn't need this ability.
  95.  
  96.   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
  97.   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
  98.  
  99.   dnl At times (like when building shared libraries) you may want
  100.   dnl to know which OS platform Python thinks this is.
  101.  
  102.   AC_CACHE_CHECK([for $am_cv_pathless_PYTHON platform],
  103.              [am_cv_python_platform],
  104.     [am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
  105.   AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
  106.  
  107.  
  108.   dnl Set up 4 directories:
  109.  
  110.   dnl pythondir -- where to install python scripts.  This is the
  111.   dnl   site-packages directory, not the python standard library
  112.   dnl   directory like in previous automake betas.  This behaviour
  113.   dnl   is more consistent with lispdir.m4 for example.
  114.   dnl
  115.   dnl Also, if the package prefix isn't the same as python's prefix,
  116.   dnl then the old $(pythondir) was pretty useless.
  117.  
  118.   AC_SUBST([pythondir],
  119.        [$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages])
  120.  
  121.   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
  122.   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
  123.   dnl   more consistent with the rest of automake.
  124.   dnl   Maybe this should be put in python.am?
  125.  
  126.   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
  127.  
  128.   dnl pyexecdir -- directory for installing python extension modules
  129.   dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
  130.  
  131.   AC_SUBST([pyexecdir],
  132.        [${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages])
  133.  
  134.   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
  135.   dnl   Maybe this should be put in python.am?
  136.  
  137.   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
  138. ])
  139.  
  140.  
  141. # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  142. # ---------------------------------------------------------------------------
  143. # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
  144. # Run ACTION-IF-FALSE otherwise.
  145. # This test uses sys.hexversion instead of the string equivalant (first
  146. # word of sys.version), in order to cope with versions such as 2.2c1.
  147. # hexversion has been introduced in Python 1.5.2; it's probably not
  148. # worth to support older versions (1.5.1 was released on October 31, 1998).
  149. AC_DEFUN([AM_PYTHON_CHECK_VERSION],
  150.  [prog="import sys, string
  151. # split strings by '.' and convert to numeric.  Append some zeros
  152. # because we need at least 4 digits for the hex conversion.
  153. minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
  154. minverhex = 0
  155. for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
  156. sys.exit(sys.hexversion < minverhex)"
  157.   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
  158.